import { Controller, Get, Post, Body, Query } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { ArticleService } from './article.service';
import { IArticleAddRequest } from './article.interface';

@ApiTags('文章管理')
@Controller('article')
export class ArticleController {
  constructor(private readonly articleService: ArticleService) {}

  @Get('query')
  @ApiOperation({ summary: '获取文章列表' })
  queryArticleList() {
    return this.articleService.queryArticleList();
  }

  @Get('query/published')
  @ApiOperation({ summary: '获取已发布的文章列表' })
  queryPublishedArticleList() {
    return this.articleService.queryPublishedArticleList();
  }

  @Get('update-views')
  @ApiOperation({ summary: '更新文章阅读量' })
  updateArticleViews(@Query('id') id: number) {
    return this.articleService.updateArticleViews(id);
  }

  @Get('published')
  @ApiOperation({ summary: '发布文章' })
  publishedArticle(@Query('id') id: number) {
    return this.articleService.publishedArticleService(id);
  }

  @Get('query/top6')
  @ApiOperation({ summary: '获取阅读量前6的文章' })
  getTop6Article() {
    return this.articleService.getTop6Article();
  }

  @Post('insert')
  @ApiOperation({ summary: '添加文章' })
  insertArticle(@Body() body: IArticleAddRequest) {
    return this.articleService.insertArticle(body);
  }

  @Post('update')
  @ApiOperation({ summary: '更新文章' })
  updateArticle(@Body() body: any) {
    return this.articleService.updateArticle(body.id, body);
  }

  @Post('remove')
  @ApiOperation({ summary: '删除文章' })
  removeArticle(@Body() body: { id: number }) {
    return this.articleService.removeArticle(body.id);
  }

  @Get('detail')
  @ApiOperation({ summary: '获取文章详情' })
  getArticleDetail(@Query('id') id: number) {
    return this.articleService.getArticleDetail(id);
  }

  @Post('like')
  @ApiOperation({ summary: '点赞文章' })
  likeArticle(@Query('id') id: number) {
    return this.articleService.likeArticle(id);
  }

  @Get('hot')
  @ApiOperation({ summary: '获取热门文章（按阅读量和点赞量排序，取前5）' })
  getHotArticles() {
    return this.articleService.getHotArticles();
  }

  @Get('latest')
  @ApiOperation({ summary: '获取最新文章（按发布时间排序，取前9）' })
  getLatestArticles() {
    return this.articleService.getLatestArticles();
  }
}
